<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="zh-cn">
    <head>
        <!-- Bootstrap -->
        <include file="Include/css" />
        <title>用户管理</title>
        <link href="__STATICS__/css/admin/index.css" rel="stylesheet">
        <link href="__STATICS__/css/sweet-alert.css" rel="stylesheet">
        <script type="text/javascript" src="__STATICS__/js/sweet-alert.min.js"></script>
        <style>
            .nav-page {
                text-align: right;
                font-size: 12px;
            }
        </style>
    </head>
    <body>
        <include file="Include/nav_top" />
        <div class="container clearfix" id="left_menu_wraper" >
            <include  file="Include/menu_left" />
            <div id="right-content">
                <div id="right-content-inner">
                    <ul class="breadcrumb">
                        <span>您的位置：</span>
                        <li><a href="{:U('Houtai/Index/index')}">首页</a> </li>
                        <li class="">用户管理</li>
                        <li class="active">用户列表</li>
                    </ul>

                    <div role="tabpanel">
                        
                        <div class="row clearfix margin10 form-horizontal">
                            <form  name="query" method="POST" >
                                <span class="pull-left ml30 form_bar">查询：</span>
                                <div class="col-md-2">
                                    <input type="text" name="sPhone" value="{$Think.post.sPhone}" placeholder=" 手机号" class="pull-left ml10 form-control" />
                                </div>
                                <div class="col-md-2">
                                    <input type="text" name="sNickName" value="{$Think.post.sNickName}" placeholder=" 昵称" class="pull-left ml10 form-control" />
                                </div>
                                <div class="col-md-2">
                                    <input type="text" name="sChannelID" value="{$Think.post.sChannelID}" placeholder=" 渠道编号" class="pull-left ml10 form-control" />
                                </div>
                                <button type="submit" class="pull-left btn btn-default ml20">
                                    搜索
                                </button>
                            </form>
                            <div class="pull-right">
                                    <button id="export_excel" class="pull-left btn btn-orange ml20">
                                        导出
                                    </button>
                            </div>
                        </div>

                        <table class="table table-striped table_qrcode">
                            <!--<caption>标题</caption>-->
                            <thead>
                                <tr class="border">
                                    <th>编号</th>
									<th>渠道编号</th>
                                    <th>头像</th>
                                    <th>昵称</th>
                                    <th>车主姓名</th>
                                    <th>手机号</th>
                                    <th>性别</th>
                                    <th>可评论</th>
                                    <th>冻结状态</th>
                                    <th>添加时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <volist name="list" id="vo">
                                    <tr class="qr_tar">
                                        <td>
                                            {$i+$num}
                                        </td>
										<td>
                                            {$vo.channelID}
                                        </td>
                                        <td >
                                            <img src="<empty name="vo['headImg']">__STATICS__/images/user_logo.png<else />{$vo.headImg}</empty>" class="img-circle" width="60" height="60" >
                                        </td>
                                        <td >{$vo.nickName}</td>
                                        <td >{$vo.carMenName}</td>
                                        <td>{$vo.phone}</td>
                                        <td><switch name="vo.sex" >
                                            <case value="0" >女</case>
                                            <case value="1">男</case>
                                            </switch>
                                        </td>
                                        <td><switch name="vo.canComment" >
                                            <case value="0" >否</case>
                                            <case value="1">是</case>
                                            </switch>
                                        </td>
                                        <td><switch name="vo.isFreeze" >
                                            <case value="0" ></case>
                                            <case value="1">已冻结</case>
                                            </switch>
                                        </td>
                                        <td>{$vo.addTime|date="Y/m/d H:i:s",###}</td>
                                        
                                        <td data-id="{$vo.userID}" >
                                            <a href="javascript:void(0)" class="edit_look" title="查看基本信息" >基本信息</a> / 
                                            <a href="javascript:void(0)" class="card_look" title="查看该用户已绑定的汇通卡" >已绑汇通卡</a>
                                        </td>
                                    </tr>
                                </volist>
                            </tbody>
                        </table>

                        <div class="clearfix s_page pull-right">
                            {$page}
                        </div>

                    </div>

                </div>

            </div>
        </div>

        <!-- 编辑基本信息-开始-->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content ">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel"> </h4>
                    </div>
                    <div class="modal-body">
                        
                        <div class="clearfix">
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        用户头像：
                                    </div>
                                    <div class="col-md-6">
                                        <img id="headImg" width="140px" height="140px" src="" class="img-rounded">
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        添加时间：
                                    </div>
                                    <div class="col-md-6">
                                        <span id="addTime"></span>
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        手机号：
                                    </div>
                                    <div class="col-md-6">
                                        <input class="form-control" type="text" id="phone" />
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        邮箱：
                                    </div>
                                    <div class="col-md-6">
                                        <input class="form-control" type="text" id="email" />
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        昵称：
                                    </div>
                                    <div class="col-md-6">
                                        <input class="form-control" id="nickName" type="text" />
                                    </div>
                                </div>
                            <div class="col-md-12 margin10">
                                <div class="col-md-3 text_right form_bar">
                                        性别：
                                </div>
                                <div class="col-md-4">
                                   <!--<div class="col-md-12 margin10">-->
                                        <div class="btn-group clearfix" data-toggle="buttons">
                                            <label class="btn btn-warning ">
                                                <input name="sex" type="radio" id="sex_1" autocomplete="off" value="1"> 男
                                            </label>
                                            <label class="btn btn-warning ">
                                                <input name="sex" type="radio" id="sex_0" autocomplete="off" value="0"> 女
                                            </label>
                                        </div>
                                    <!--</div>-->
                                </div>
                            </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        车牌号：
                                    </div>
                                    <div class="col-md-6">
                                        <input id="carNum" type="text"  class="form-control">
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        车型：
                                    </div>
                                    <div class="col-md-6">
                                         <input id="carType" type="text" class="form-control" />
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        车主姓名：
                                    </div>
                                    <div class="col-md-6">
                                         <input id="carMenName" type="text" class="form-control" />
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        身份证：
                                    </div>
                                    <div class="col-md-6">
                                         <input id="idcard" type="text" class="form-control" />
                                    </div>
                                </div>
                                <div class="col-md-12 margin10">
                                    <div class="col-md-3 text_right form_bar">
                                        车辆品牌：
                                    </div>
                                    <div class="col-md-6">
                                        <input id="carBrand" type="text" class="form-control" />
                                    </div>
                                </div>
                            <div class="col-md-12 margin10">
                                <div class="col-md-3 text_right form_bar">
                                        是否可评论：
                                </div>
                                <div class="col-md-6">
                                   <!--<div class="col-md-12 margin10">-->
                                        <div class="btn-group clearfix" data-toggle="buttons">
                                            <label class="btn btn-warning ">
                                                <input name="canComment" type="radio" id="com_1" autocomplete="off" value="1"> 可评
                                            </label>
                                            <label class="btn btn-warning ">
                                                <input name="canComment" type="radio" id="com_0" autocomplete="off" value="0"> 禁言
                                            </label>
                                        </div>
                                    <!--</div>-->
                                </div>
                            </div>
                            <div class="col-md-12 margin10">
                                <div class="col-md-3 text_right form_bar">
                                        冻结状态：
                                </div>
                                <div class="col-md-6">
                                   <!--<div class="col-md-12 margin10">-->
                                        <div class="btn-group clearfix" data-toggle="buttons">
                                            <label class="btn btn-warning ">
                                                <input name="isFreeze" type="radio" id="isFreeze_1" autocomplete="off" value="1"> 冻结
                                            </label>
                                            <label class="btn btn-warning ">
                                                <input name="isFreeze" type="radio" id="isFreeze_0" autocomplete="off" value="0"> 解冻
                                            </label>
                                        </div>
                                    <!--</div>-->
                                </div>
                            </div>
                            <div class="col-md-12 margin10">
                                <div class="col-md-3 text_right form_bar">
                                    提示信息：
                                </div>
                                <div class="col-md-8">
                                    <textarea id="errorMsg" class="form-control" ></textarea>
                                </div>
                            </div>
                            <div class="col-md-12 margin10">
                                <div class="col-md-3 text_right form_bar">
                                    渠道编号：
                                </div>
                                <div class="col-md-6">
                                    <span id="channelID"></span>
                                </div>
                            </div>
                                
                    </div>
                        
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" id="save" >保存</button>
                    <input type="hidden" id="userID" />
                </div>
            </div>
            </div>
        </div><!--编辑基本信息-结束-->
            
        <!--优惠券已发布的用户-开始--->
        <div class="modal fade" id="release_user" tabindex="-1" role="dialog" aria-labelledby="myModalReleaseUser" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalReleaseUser"> </h4>
                    </div>
                    <div class="modal-body">
                        <table class="table table-striped table_qrcode">
                            <!--<caption>标题</caption>-->
                            <thead>
                                <tr class="border">
                                    <th>汇通卡号</th>
                                    <th>绑定时间</th>
                          
                                </tr>
                            </thead>
                            <tbody id="user_list_coupon">
                          
                                   
                            </tbody>
                        </table>
                        <nav class="nav-page">
                            <span class="rows" id="pagination"><a href="javascript:void(0);">共 0 条记录</a></span>
                        </nav>
                    </div>
       
                </div>
            </div>
        </div><!--优惠券已发布的用户-结束--->

        <include file="Include/script" />
        <script>
            var reload = false;
            var img_url = "__STATICS__/images";
            var card_url = "{:U('CNEPAdmin/UserCard/cardList')}";
            
            /*菜单展开及高亮*/
            $(function () {
                $('.user').addClass('open');
                $('#user2').addClass('active');

                $('#myModal').on('hidden.bs.modal', function (e) {
                    if(reload) {
                        window.location.reload();
                    }
                 });
                /*编辑*/
                $(".edit_look").on("click", function () {
                    var userID = $(this).closest("td").attr("data-id");
                    var jsonData = {};
                    jsonData.userID = userID;
                    ajax_go_1(jsonData,"{:U('CNEPAdmin/User/userMsg')}",onEdit);
                    
                });
                
                function onEdit(rsp) {
                    
                    $("#headImg").attr('src',rsp.headImg);
                    $("#addTime").html(rsp.addTime);
                    $("#nickName").val(rsp.nickName);
                    $("#idcard").val(rsp.idcard);
                    $("#errorMsg").val(rsp.errorMsg);
                    $("#carNum").val(rsp.carNum);
                    $("#carType").val(rsp.carType);
                    $("#carMenName").val(rsp.carMenName);
                    $("#carBrand").val(rsp.carBrand);
                    $("#phone").val(rsp.phone);
                    $("#email").val(rsp.email);
                    $("#userID").val(rsp.userID);
                    $("#channelID").html(rsp.channelID);
                    
                    $(":radio[name='sex']").each(function(){if($(this).val() == rsp.sex)$(this).click()});
                    $(":radio[name='canComment']").each(function(){if($(this).val() == rsp.canComment)$(this).click()});
                    $(":radio[name='isFreeze']").each(function(){if($(this).val() == rsp.isFreeze)$(this).click()});
                     
                    $("#myModalLabel").html("用户信息");
                    $('#myModal').modal(); // 跳出弹窗
                }
                
                /*保存*/
                $("#save").on("click", function () {
                    var jsonData = {};
                    jsonData.nickName = $("#nickName").val();
                    jsonData.idcard = $("#idcard").val();
                    jsonData.errorMsg = $("#errorMsg").val();
                    jsonData.carNum = $("#carNum").val();
                    jsonData.carType = $("#carType").val();
                    jsonData.carMenName = $("#carMenName").val();
                    jsonData.carBrand = $("#carBrand").val();
                    jsonData.phone = $("#phone").val();
                    jsonData.email = $("#email").val();
                    jsonData.userID = $("#userID").val();

                    jsonData.sex = $(":radio[name='sex']:checked").val();
                    jsonData.canComment = $(":radio[name='canComment']:checked").val();
                    jsonData.isFreeze = $(":radio[name='isFreeze']:checked").val();

                    ajax_go_1(jsonData,"{:U('CNEPAdmin/User/updateUserMsg')}",onSave);
                    
                });
                function onSave(rsp) {
                    if(rsp.result > 0) {
                        swal("保存成功","","success");
                        reload = true;
                    } else {
                        swal("保存失败;"+rsp.desc,"","error");
                    }
                    
                }
                
                /*弹出框隐藏后*/
                $('#myModal').on('hidden.bs.modal', function (e) {
                    if(reload) {
                        window.location.reload();
                    }
                     reset_display();
                });

                /*清空弹出框内容*/
                function reset_display()
                {
                    $("#headImg").attr('src',"");
                    $("#addTime").html("");
                    $("#nickName").val("");
                    $("#idcard").val("");
                    $("#errorMsg").val("");
                    $("#carNum").val("");
                    $("#carType").val("");
                    $("#carMenName").val("");
                    $("#carBrand").val("");
                    $("#phone").val("");
                    $("#email").val("");
                    $("#userID").val("");
                    
                }
             
             $(".card_look").on("click",function(){
                    var userID   = $(this).closest("td").attr("data-id");
                    //couponsUser
                    $("#myModalReleaseUser").html("已绑汇通卡");
                    $('#release_user').modal(); // 跳出弹窗
                   var ajaxData = {};
                    ajaxData.userID = userID;
                   load_card(ajaxData);
                   
                });
                
                
               function load_card(ajaxData){
                   ajax_go_1(ajaxData ,card_url,list_callback);
               }   
             
            //查看已绑汇通卡时回调
            function list_callback(rsp){
                
                var html ='';
                var result = rsp.result;
                if(result<1){
                    swal('获取信息失败!'+rsp.desc,'','warning');
                }else{
                   var list = rsp.list;
                   for(var i=0;i<list.length;i++){
                        html+='<tr class="qr_tar">';
                        html+='<td>'+list[i].cardNum+'</td>';//
                        html+='<td>'+list[i].addTime+'</td>';//
                        html+='</tr>';
                   }
                }
                 $("#user_list_coupon").html(html);
                 $("#pagination").html("<a href=\"javascript:void(0);\">共 "+rsp.totalRow+" 条记录</a>");
            }

            /*取消订单*/
            $("#export_excel").on("click", function () {
                
                swal({   
                    title: "您确定吗?",
                    text: "您将导出Excel表单！",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    cancelButtonText: "放弃",
                    closeOnConfirm: true
                    },
                    function (isConfirm) {
                        if (isConfirm) {
                            var param = "sPhone={$Think.request.sPhone}&sNickName={$Think.request.sNickName}&sChannelID={$Think.request.sChannelID}";
                            window.location.href = "{:U('CNEPAdmin/Excel/userReport')}?"+param;
                        }

                    });
            });

                
            });
                                    
        </script>
    </body>
</html>